<!DOCTYPE HTML>
<html>
<head>
    <title>设备报修</title>
    <% include common/meta.ejs %>
    <% include common/public.ejs %>
    <style>
        .weui_uploader_file img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body ontouchstart="">
<form id="reservedForm">
    <div class="weui_cells weui_cells_form">
        <input type="hidden" name="issueUser" value="<%= userData.id %>">
        <input type="hidden" name="name" value="<%= userData.name %>">
        <input type="hidden" name="userImg" value="<%= userData.headimgurl %>">
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label" for="name">设备类型</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input type="text" id="equipmentType" name="type" class="weui_input" readonly="">
            </div>
        </div>

        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">联系人员</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name="contactName" placeholder="可以联系的人员姓名"
                       value="<%= userData.name %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">联系手机</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="tel" name="contactPhone" placeholder="联系的手机好"
                       value="<%= userData.phone %>">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">详细地址</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name="address" placeholder="详细地点">
            </div>
        </div>
    </div>

    <div class="weui_cells_title">详细描述</div>
    <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_bd weui_cell_primary">
                <textarea class="weui_textarea" name="remark" placeholder="请描述报修的设备的问题" rows="3"></textarea>
            </div>
        </div>
    </div>

    <!--<div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_bd weui_cell_primary">
                <div class="weui_cells_title">图片上传</div>
                <div class="weui_uploader">
                    <div class="weui_uploader_bd">
                        <ul class="weui_uploader_files" id="weui_uploader_files">
                            &lt;!&ndash;<li class="weui_uploader_file">&ndash;&gt;
                            &lt;!&ndash;<img src="http://gy.rechange.cn/yams-upload/images/IBuq9ljLuQqssZojXRdLYU8Pd8uqxWEz85bQOIVGegEHRkbvtK9od7T6I0QXe2Op.jpg">&ndash;&gt;
                            &lt;!&ndash;</li>&ndash;&gt;
                        </ul>
                        <div class="weui_uploader_input_wrp">
                            <input name="mediaIds" type="hidden" id="media_ids_input"/>
                            <input class="weui_uploader_input" type="button" id="imageUpload"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>-->
</form>
<div style="text-align: center;width: 100%;padding: 20px 0;">
    <button style="margin-top: 20px;margin-bottom: 10px;" id="repairSubmit" class="weui_btn weui_btn_warn">报修设备</button>
    <a href="repairList?openId=<%= session.openId %>" style="color: #3ab6b4;font-size: 0.7rem;margin-bottom: 10px;">查看我的报修历史</a>
</div>

<% include common/footer.ejs %>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    $("#equipmentType").select({
        title: "选择设备类型",
        items: [
            {
                title: "电器",
                value: "001",
            },
            {
                title: "下水道",
                value: "002",
            },
            {
                title: "家具",
                value: "003",
            }
        ]
    });

    $("#repairSubmit").click(function () {
        $.confirm({
            title: '报修设备确认',
            text: '确认要报修此设备吗？',
            onOK: function () {
                $.showLoading();
                var data = Dolphin.form.getValue("#reservedForm");
                console.log(data);
                Dolphin.ajax({
                    url: CTX + '/api/fcca1aa0e7554b2bb871d3a1b8a7df36',
                    type: 'put',
                    forceUrl: 'true',
                    data: Dolphin.json2string(data),
                    onSuccess: function () {
                        location.href = CTX + "/view/repairList";
                    },
                    onComplete: function () {
                        $.hideLoading();
                    }
                })
            },
            onCancel: function () {
            }
        });
    });

    <!--alert(location.href.split('#')[0]+'&<%= data.appId %>&<%= data.timestamp %>&<%= data.nonceStr %>&<%= data.signature %>');-->
    //----------wechat js sdk-----------
    wx.config({
        debug: false,
        appId: "<%= data.appId %>", // 必填，公众号的唯一标识
        timestamp: "<%= data.timestamp %>",
        nonceStr: "<%= data.nonceStr %>",
        signature: "<%= data.signature %>",
        jsApiList: [  // 必填，需要使用的JS接口列表
            "chooseImage",
            "previewImage",
            "uploadImage",
            "downloadImage"
        ]
    });

    wx.ready(function () {
        $('#weui_uploader_files').click(function (e) {
            var image_files = $(this).children('.weui_uploader_file');
            if (image_files.length > 0) {
                var urls = [];
                image_files.each(function (i, li) {
                    urls.push($(li).attr('imgSrc'));
                })
                wx.previewImage({
                    current: $(e.target).attr('imgSrc'), // 当前显示图片的http链接
                    urls: urls // 需要预览的图片http链接列表
                });
            }
        });
        $('#imageUpload').click(function () {
            var total, panel = $('#weui_uploader_files');
            total = panel.children('.weui_uploader_file').length;
            wx.chooseImage({
                count: 5 - total, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds,localId; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    if (localIds && localIds.length > 0) {
                        for(var i=0;i<localIds.length;i++){
                            localId = localIds[i];
                            wx.uploadImage({
                                localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
                                isShowProgressTips: 1, // 默认为1，显示进度提示
                                success: function (res) {
                                    var serverId = res.serverId; // 返回图片的服务器端ID
                                    if (serverId) {
                                        Dolphin.ajax({
                                            url: '<%= global.config.contextPath == '/' ? '' : global.config.contextPath %>/wexin/downloadImage?catalog=repair&mediaId=' + serverId,
                                            type: Dolphin.requestMethod.GET,
                                            forceUrl: true,
                                            onSuccess: function (reData) {
                                                var value = $('#media_ids_input').val();
                                                if (value.length != 0) {
                                                    value += ',';
                                                }
                                                $('#media_ids_input').val(value + serverId);
                                                //http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=?&media_id=?
                                                $('<li class="weui_uploader_file" imgSrc="'+localId+'">' +
                                                    '<img src="'+reData.url+'" alt="'+serverId+'" />' +
                                                    '</li>')
                                                    .appendTo(panel);
                                                if (panel.children('.weui_uploader_file').length == 4) {
                                                    $('#imageUpload').hide();
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            });
        });
    });
    wx.error(function (res) {
        alert("<%= __('service.his.weixin.err') %>");
    });

</script>
</body>
</html>